import { App, ipcMain, IpcMainEvent } from 'electron'
import listener from './listener'

type EventParamsType = {
    success: boolean,
    value: any,
    next: string
}

export class BackExchange{
    constructor( app: App ){
        ipcMain.on('exchange', listener.route )
        ipcMain.on('asyncExchange', listener.asyncRoute )
    }

    // exchangeHandler(message:string){
    //     const args = Array.prototype.slice.call(arguments, 1)
    //     const msgTag = message.replace(/\-/g, '_');
    //     if( Listens[msgTag] instanceof Function){
    //         const re = Listens[msgTag].apply( this, args )
    //         return re
    //     }
    //     return null
    // }

    put(){

    }

    // asyncPut(message: string, params: any = null, scope: any = null): EventParamsType{
    //     // const key: string = ( 'before_' + (message||'') )
    //     // let p = params
    //     // if( BeforeSend[key] instanceof Function){
    //     //     p = BeforeSend[key].apply( scope || this, [params])
    //     // }
    //     // return IPC.sendSync('exchange', message, p)
    // }
}

export default BackExchange